package ks.client.gui.admin.plugin.listeners;
	
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import ks.managers.plugin.Plugin;


/**
 * PluginModel used for the table in the Admin Plugin Controls GUI.
 * 
 * @author Jennifer Hunt
 *
 */
public class PluginModel extends AbstractTableModel{

	private static final long serialVersionUID = 6197136671891123577L;
	/** Elements for the model. */
	ArrayList<Plugin> pluginList;
	
	public PluginModel () {
		this.pluginList = new ArrayList<Plugin>();
	}
	
	public int getColumnCount() {
		return 2;
	}

	public int getRowCount() {
		return pluginList.size();
	}

	/**
	 * Add a plugin to the list
	 * 
	 * @param p
	 * @return
	 */
	public boolean add(Plugin p) {
		return pluginList.add(p);
	}
	
	/**
	 * Remove from the model by actual Plugin object which is compared via equals
	 * method.
	 * 
	 * @param p
	 * @return
	 */
	public boolean remove(Plugin p) {
		return pluginList.remove(p);
	}

	
	/**
	 * Remove from the model by name
	 * 
	 * @param make
	 * @return
	 */
	public boolean remove(String name) {
		for (int i = 0 ; i < pluginList.size(); i++) {
			Plugin p = pluginList.get(i);
			if (p.name.equalsIgnoreCase (name)) {
				return pluginList.remove(p);
			}
		}
		
		return false;
	}
	
	/**
	 * Remove all the plugins from the model.
	 * 
	 * @return
	 */
	public boolean removeAll(){
		for (int i = 0 ; i < pluginList.size(); i++) {
			Plugin p = pluginList.get(i);
			pluginList.remove(p);
		}
		return false;
	}
	
	public Object getValueAt(int rowIndex, int columnIndex) {
		Plugin p = pluginList.get(rowIndex);
		
		if (columnIndex == 0) {
			//Name 
			return p.getName();
		} else if (columnIndex == 1) {
			//Suspended or not
			return p.getSuspended();//getSuspended();
		}
		// no idea who you are...
		return "";
	}

}
